﻿component accessors="true" extends="controllerbase" {
	property user;
	this.entityObj = "user";

	public void function list(rc)
	{
		var moduleSqlWhere = "";
		if( structKeyExists(rc, "loginname") && len(trim(rc.loginname)) >0 ){
			moduleSqlWhere = moduleSqlWhere & " and loginname like '%" & loginname & "%' " ;
		}
		
		if( structKeyExists(rc, "name") && len(trim(rc.name)) >0 ){
			moduleSqlWhere = moduleSqlWhere & " and name like '%" & name & "%' " ;
		}
		
		if( structKeyExists(rc, "sex") && len(trim(rc.sex)) >0 ){
			moduleSqlWhere = moduleSqlWhere & " and sex = " & rc.sex ;
		}
		
		super.list(rc,moduleSqlWhere);
	}
	
	//角色权限树内容
	public void function getRoleGrantTree(rc){
		rc.json = variables.user.getRoleGrantTree(rc.id);
		variables.fw.renderData('json', rc.json);
	}
	
	//保存角色授权
	public void function saveRoleGrant(rc){
		rc.data = variables.user.saveRoleGrant(rc);
		variables.fw.renderData('json', true);
	}
	
	//组织机构权限树内容
	public void function getOrganizationGrantTree(rc){
		rc.json = variables.user.getOrganizationGrantTree(rc.id);
		variables.fw.renderData('json', rc.json);
	}
	
	//保存组织机构授权
	public void function saveOrganizationGrant(rc){
		rc.data = variables.user.saveOrganizationGrant(rc);
		variables.fw.renderData('json', true);
	}
	
	//登陆
	public void function login(rc){
		rc.user = variables.user.login(rc);
       	session.auth.isloggedin = true;
        session.auth.userid = rc.user.getId();
		variables.fw.renderData('json', true);
	}
	
	//退出
	function logout(rc) {
        session.auth.isloggedin = false;
        variables.fw.redirect("main.default");
    }
    
    
    public void function getOrgRoleUser(rc){
    	
		if( structKeyExists(rc, "organizationids")  && listlen(rc.organizationids) > 0 ){
			rc.organizationids = rc.organizationids;
		}else{
			rc.organizationids = 0;
		}
		
		if( structKeyExists(rc, "roleids")  && listlen(rc.roleids) > 0 ){
			rc.roleids = rc.roleids;
		}else{
			rc.roleids = 0;
		}
		
		if( structKeyExists(rc, "userids")  && listlen(rc.userids) > 0 ){
			rc.userids = rc.userids;
		}else{
			rc.userids = 0;
		}
    	
		rc.data = variables.user.getOrgRoleUser(rc);
		variables.fw.renderData('json', rc.data);
	}
	
	public void function getUserCount(){
		rc.data = variables.user.getUserCount();
		variables.fw.renderData('json', rc.data);
	}
    
}